using System;
using System.Collections.Generic;
using System.Text;

using DDay.iCal;
using DDay.iCal.Components;
using DDay.iCal.Serialization;
using DDay.iCal.DataTypes;

namespace quickTask
{
    public class CalendarWorker
    {
        public CalendarWorker(string file)
        {
            load(file);
        }

        public CalendarWorker()
        {
            mCalendar = new iCalendar();
        }

        public int CountTodosAll
        {
            get { return mCalendar.Todos.Count; }
        }

        public void load(string file)
        {
            mCalendar = iCalendar.LoadFromFile(file);
        }

        public void save(string file)
        {
            iCalendarSerializer serializer = new iCalendarSerializer(mCalendar);
            serializer.Serialize(file);
        }

        public void addTodo(string summary, string description, 
            string category)
        {
            Todo newTodo = mCalendar.Create<Todo>();
            newTodo.Summary = summary;

            if(description != "") newTodo.Description = description;
            if(category != "") newTodo.AddCategory(category);
        }

        public Todo find(string summary)
        {
            foreach(Todo theTodo in mCalendar.Todos)
            {
                if (theTodo.Summary == summary) return theTodo;
            }

            return null;
        }


        private iCalendar mCalendar;

    }
}
